import { Injectable } from '@angular/core';
import { HttpService } from '../providers/HttpService';
import { map, mergeMap } from 'rxjs/operators';
import { Observable, of } from 'rxjs';
import { FileService } from '../providers/FileService';
import { ValidationErrors } from '@angular/forms';
import * as constants from '../providers/Constants'
import { Helper } from '../providers/Helper';

@Injectable({
    providedIn: 'root'
})
export class OrderService {
    constructor(public http: HttpService, public fileService: FileService,private mHelper:Helper) {
    }

    // 获取商品订单列表
    queryProcOrder(data) {
        return this.http.post(constants.ApiServeLogin.queryProcOrder, data, {
            showLoading: false
        });
    }

    // 获取商品订单详情
    queryProcOrderDetail(data) {
        return this.http.post(constants.ApiServeLogin.queryProcOrderDetail, data);
    }
  // 获取商品订单详情
     markSureProcOrder(data) {
        return this.http.post(constants.ApiServeLogin.markSureProcOrder, data);
    }

    // 获取合同列表
    getRate(data) {
        return this.http.post(constants.ApiServeLogin.getRate, data,{showLoading:false});
    }

      // 创建订单
      markSureOrder(data) {
        return this.http.post(constants.ApiServeLogin.markSureOrder, data, { showLoading: true });
    }
    // 创建订单
    cashPlaceOrder(data) {
        return this.http.post(constants.ApiServeLogin.cashPlaceOrder, data, { showLoading: true });
    }

    // 查询费率
    getQueryRate(data) {
        return this.http.post(constants.ApiServeLogin.queryRate, data);
    }
    // 获取物流
    queryMerchAddress(data) {
        return this.http.post(constants.ApiServeLogin.queryMerchAddress, data);
    }
    // 下单
    placeOrder(data) {
        return this.http.post(constants.ApiServeLogin.placeOrder, data);
    }
    // 获取银行卡列表
    getSelCard(data) {
        return this.http.post(constants.ApiServeLogin.getSelCard, data,{showLoading:false});
    }
    // 删除银行卡列表
    delCard(data) {
        return this.http.post(constants.ApiServeLogin.delCard, data);
    }

    // 请求支付数据
    ordderConfirm(data) {
        if (this.mHelper.isAndroid()) {
            data.terminalType="0"
        }else if (this.mHelper.isIos()) {
            data.terminalType="1"
        }else{
            data.terminalType="0" 
        }
        return this.http.post(constants.ApiServeLogin.ordderConfirm, data);
    }
    // 请求支付数据
    againplaceorder(data) {
        if (this.mHelper.isAndroid()) {
            data.terminalType="0"
        }else if (this.mHelper.isIos()) {
            data.terminalType="1"
        }else{
            data.terminalType="0" 
        }
        return this.http.post(constants.ApiServeLogin.againPlaceOrder, data);
    }
    // 退款
    orderRefund(data) {
        return this.http.post(constants.ApiServeLogin.orderRefund, data);
    }

     // 退款
     treatyflagQueryAddress(data) {
        return this.http.post(constants.ApiServeLogin.treatyflagQueryAddress, data);
    }

    // 删除id
    cancelOrder(data) {
        return this.http.post(constants.ApiServeLogin.cancelOrder, data);
    }

     // 查询购销协议书
     queryBuyTreaty(data) {
        return this.http.post(constants.ApiServeLogin.queryBuyTreaty, data);
    }
    // 获取图片地址
    getImageUrl() {
        return this.http.getImageUrl();
    }
   // 创建订单
   markSureOrderData(data) {
    return this.http.post(constants.ApiServeLogin.markSureOrderData, data, { showLoading: false });
}
}
